﻿using System;
using System.Collections.Generic;
using GoogleEarthClasses.Entities;
using GoogleEarthClasses.Logic;
using System.ComponentModel;
using System.Data.SqlClient;
using GoogleEarthClasses.Data;
namespace GoogleEarthClasses.Global
{
    public class Server
    {

        #region ProtectedProperties
        protected List<EPoint> m_Points;
        protected DateTime m_DateStart = System.DateTime.Now.AddDays(-10);
        protected DateTime m_DateEnd = System.DateTime.Now.AddDays(+1);
        protected int m_TotalImages;

        protected List<EPolygonType> m_PolygonTypes;
        #endregion

        #region PublicMembers
        public List<EPoint> Points
        {
            get { return m_Points; }
            set { m_Points = value; }
        }
        public DateTime DateStart 
        {
            get { return m_DateStart; }
            set { m_DateStart = value; }
        }
        public DateTime DateEnd 
        {
            get { return m_DateEnd; }
            set { m_DateEnd = value; }
        }
        public List<EPolygonType> PolygonTypes
        {
            get { return m_PolygonTypes; }
            set { m_PolygonTypes = value; }
        }

        #endregion


        public Server()
        { }
        /// <summary>
        /// connect to the server and download the points between dateStart and dateEnd
        /// </summary>
        public void LoadServerPoints()
        {
            m_Points = LPoint.SelectAll(m_DateStart,m_DateEnd);
        }
        /// <summary>
        /// connect to the server and download the existing polygons types with their polygons
        /// </summary>
        public void LoadServerPolygonTypes()
        {
            m_PolygonTypes = LPolygonType.SelectAll();
        }

        /// <summary>
        /// test the connection to the server
        /// </summary>
        /// <returns>true is succesfull,</returns>
        public static bool TestConnection()
        {
            return DBHelper.TestMasterConnection();
        }

        protected void GetTotalImages()
        {
            m_TotalImages = 0;
            foreach (EPoint Point in m_Points)
            {
                m_TotalImages += Point.HaveImages;
            }
        }

        public Int32 PolygonInsert(EPolygon Polygon) {
            return LPolygon.Insert(Polygon);
        }
        public void PolygonUpdate(EPolygon Polygon)
        {
            LPolygon.Update(Polygon);
        }
        public void PolygonDelete(EPolygon Polygon)
        {
            LPolygon.Delete(Polygon);
        }
    }
}
